package com.example.arithmeticleetcode.leetcode.nov;


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-11-27 09:23
 **/
public class Demo21 {

    public static void main(String[] args) {
        Map<Integer, Character> map = new HashMap<>();
        int charValue = 97;
        for (int i = 1; i < 27; i++) {
            map.put(i, (char)charValue++);
        }
        System.out.println(map);

        String str = "12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#";
        System.out.println(freqAlphabets(str));
    }

    public static String freqAlphabets(String s) {
        Map<Integer, Character> map = new HashMap<>();
        int charValue = 97;
        for (int i = 1; i < 27; i++) {
            map.put(i, (char)charValue++);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == '#') {
                int temp = i;
                i  = i - 2;
                String s1 = s.substring(i, temp);
                Character character = map.get(Integer.valueOf(s1));
                sb.append(character);
            } else {
                Character character = map.get((s.charAt(i) - 48));
                sb.append(character);
            }

        }
        return sb.reverse().toString();
    }
}
